package com.example.demo.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("mapping") //访问路径必须加上mapping也就是：root/mapping/xx
public class MappingController {

	/**
	 * http://127.0.0.1:9999/root/mapping/test_get
	 * @return
	 */
	@RequestMapping(value="test_get",method=RequestMethod.GET)
	public String testGet() {
		return "mapping/index";
	}
	/**
	 * 与上面的请求方式一致
	 * @return
	 */
	@GetMapping("test_get2")
	public String test2Get() {
		return "mapping/index";
	}
	/**
	 * 参数过滤
	 * @return
	 */
	@RequestMapping(value="testParam",params={"name","age!=10","!sex"})
	public String testParam() {
		return "mapping/param";
	}
	
	/**
	 * 请求头过滤
	 * @return
	 */
	@RequestMapping(value="testheaders",headers={"Accept-Encoding=gzip, deflate, br"})
	public String testheaders() {
		return "mapping/param";
	}
	/**
	 * http://127.0.0.1:9999/root/mapping/tongPei/haha/mizz?name=wangwu&age=20
	 * @return
	 */
	@RequestMapping(value="tongPei/*/mi??")
	public String tongPei() {
		return "mapping/param";
	}
	/**
	 * 路径参数
	 * http://127.0.0.1:9999/root/mapping/pathVal/李四/18
	 * @param name
	 * @param age
	 * @param map
	 * @return
	 */
	@RequestMapping(value="pathVal/{name}/{age}")
	public String pathVal(@PathVariable String name,
			@PathVariable Integer age,Map<String,Object> map) {
		map.put("name", name);
		map.put("age", age);
		return "mapping/pathValue";
	}
	
}
